package com.csf.common.utils;

import java.net.InetAddress;

import org.jboss.netty.channel.ChannelFuture;
import org.jboss.netty.channel.ChannelFutureListener;
import org.jboss.netty.handler.ssl.SslHandler;

public class Greeter implements ChannelFutureListener  {

	private final SslHandler sslHandler;

	public Greeter(SslHandler sslHandler) {
		this.sslHandler = sslHandler;
	}

	@Override
	public void operationComplete(ChannelFuture future) throws Exception {
		if (future.isSuccess()) {
			// Once session is secured, send a greeting.
//			future.getChannel().write(
//					"Welcome to " + InetAddress.getLocalHost().getHostName()
//							+ " secure chat service!\n");
//			future.getChannel().write(
//					"Your session is protected by "
//							+ sslHandler.getEngine().getSession()
//									.getCipherSuite() + " cipher suite.\n");

			System.out.println("handshake complete:"+ InetAddress.getLocalHost().getHostName());

System.out.println("Your session is protected by " + sslHandler.getEngine().getSession()
									.getCipherSuite() + " cipher suite.\n"); 			
			
		} else {
			future.getChannel().close();
		}

	}
}
